#include <jni.h>
#include <string>
#include "LogUtils.h"
#include "ImuManager.h"
#include "JavaVMHelper.h"

void imu_data_callback(NxrRawData data) {
    LOGD("IMU DATA => acc[%f %f %f]\n"
         "gyro[%f %f %f]\n", data.acc[0], data.acc[1], data.acc[2],
         data.gyro[0], data.gyro[1], data.gyro[2]);
}

extern "C" JNIEXPORT void JNICALL
Java_com_taiic_fourimu_ImuManager_startImu(
        JNIEnv *env,
        jobject /* this */) {
    /*
    JavaVMHelper::getInstance().setJavaVm(nullptr);
    JavaVM *tmpVM = nullptr;
    // 获取JavaVM
    if (env->GetJavaVM((&tmpVM)) != JNI_OK || !tmpVM) {
        LOGE("Failed to get JavaVM");
    } else {
        JavaVMHelper::getInstance().setJavaVm(tmpVM); //保存 JavaVM
    }*/

    ImuManager::getInstance().registerCallback(imu_data_callback);
    ImuManager::getInstance().startImu();
}

extern "C" JNIEXPORT void JNICALL
Java_com_taiic_fourimu_ImuManager_stopImu(
        JNIEnv *env,
        jobject /* this */) {
    ImuManager::getInstance().removeCallback(imu_data_callback);
    ImuManager::getInstance().stopImu();
}


